package com.payease.ezt.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebHistoryItem;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.payease.ezt.R;

import java.util.List;

/**
 * Created by wuyong on 16/8/3.
 */
public class WebHistoryAdapter extends BaseAdapter {
    private List<WebHistoryItem> webItems;
    private Context context;
    public WebHistoryAdapter(List<WebHistoryItem> webItems, Context context) {
        this.webItems = webItems;
        this.context = context;
    }

    public void setWebItems(List<WebHistoryItem> webItems){
        this.webItems = webItems;
    }

    @Override
    public int getCount() {
        return webItems == null ? 0 : webItems.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_web_history,null);
            holder.tvWebTitle = (TextView) convertView.findViewById(R.id.tv_web_url_title);
            holder.tvWebUrl = (TextView) convertView.findViewById(R.id.tv_web_url);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvWebUrl.setText(webItems.get(position).getUrl());
//        holder.tvWebTitle.setText(webItems.get(position).getTitle());
        return convertView;
    }
    class ViewHolder{
        TextView tvWebUrl;
        TextView tvWebTitle;
    }
}
